document.getElementsByName("func_expr")[0].addEventListener("keydown", keydownhandler);
document.getElementsByName("func_expr")[0].focus();
var plot = new Fooplot(document.getElementsByName("plot")[0]);
function keydownhandler(e){
    switch (e.key){
        case "Enter":
            draw_func();
            break;
        case "Call":
            plot.deleteAllPlots();
            plot.reDraw();
            break;
        case "SoftRight":
            plot.zoom(.9);
            break;
        case "SoftLeft":
            plot.zoom(1.1);
            break;
    }

}
function draw_x2(){
    plot = new Fooplot(document.getElementsByName("plot")[0]);
    plot.addPlot('x^2', FOOPLOT_TYPE_FUNCTION, {'color': '#ff0000'});
    plot.reDraw();
}
function draw_func(){
    var func_expr = document.getElementsByName("func_expr")[0].value;
    var colors = ["green", "red", "blue", "purple", "black", "orange",
    "yellow"];
    var color = colors[Math.floor(Math.random() * colors.length)];
    plot.addPlot(func_expr, null,{"color": color});
    plot.reDraw();
}
